package mx.vlabs.soapdroid.wsdl2java.artifactbuilder;

import static mx.vlabs.soapdroid.utils.Utils.capitalizeFirstLetter;
import mx.vlabs.soapdroid.wsdl2java.Artifact;

import org.ow2.easywsdl.schema.api.Enumeration;
import org.ow2.easywsdl.schema.api.SimpleType;

public class EnumerationArtifactBuilder extends ArtifactBuilder {
	
	private SimpleType simpleType;

	public EnumerationArtifactBuilder(SimpleType simpleType,String packageName) {
		super(packageName);
		this.simpleType = simpleType;
	}

	@Override
	public String build() {
		// TODO Auto-generated method stub
		//simpleType.
		String simpleTypeNamespace = simpleType.getQName().getNamespaceURI();
		String simpleTypeName      = simpleType.getQName().getLocalPart();
		String simpleTypeClassName = capitalizeFirstLetter(simpleTypeName);
		
		getArtifact().setParam("enumName", simpleTypeClassName);
		getArtifact().setName(simpleTypeClassName);
		
		StringBuilder sb = new StringBuilder();
		boolean firstRun = true;
		
		for(Enumeration enumeration : simpleType.getRestriction().getEnumerations()){
			String prefix = firstRun ? "\t" : ",\n\t";
			sb.append(prefix).append(enumeration.getValue());
			if(firstRun) firstRun = false;
		}
		
		getArtifact().setParam("enumItems", sb.toString());
		
		return getArtifact().getContent();
	}

	@Override
	public String getArtifactType() {
		// TODO Auto-generated method stub
		return "enumeration";
	}

}
